package com.joysuch.wwyt.workflow.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import com.joysuch.wwyt.workflow.bean.WorkFlowDocBean;
import com.joysuch.wwyt.workflow.bean.WorkFlowOptionBean;
import com.joysuch.wwyt.workflow.bean.WorkFlowOptionTypeBean;
import com.joysuch.wwyt.workflow.entity.WorkFlowDoc;
import com.joysuch.wwyt.workflow.entity.WorkFlowOption;
import com.joysuch.wwyt.workflow.entity.WorkFlowOptionType;
import com.joysuch.wwyt.workflow.service.WorkFlowDocService;
import com.joysuch.wwyt.workflow.service.WorkFlowOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/workflow/doc")
@Api(tags = "业务流程文档配置管理")
@CrossOrigin
public class WorkFlowDocController {

    @Autowired
    private WorkFlowDocService workFlowDocService;



    @PostMapping("/page")
    @ApiOperation(value = "获取文档清单列表(分页）" , response = WorkFlowOption.class)
    public ResultBean page(Pageable pageable) {
       pageable= PageDataUtils.addOrderByAsc(pageable,"showOrder");
       Page<WorkFlowDoc> list = workFlowDocService.getDocList(pageable);
       return ResultBean.pageData(list);
    }


    @GetMapping("/getById")
    @ApiOperation(value = "获取文档清单(根据类型Id）" , response = WorkFlowOption.class)
    public ResultBean getById(@RequestParam Long id) {
        WorkFlowDoc workFlowDoc = workFlowDocService.findById(id);
        return ResultBean.success(workFlowDoc);
    }

    @RequiresPermissions("workflow:doc:delete")
    @GetMapping("/deleteById")
    @ApiOperation(value = "删除文档清单(根据类型Id）")
    public ResultBean deleteById(@RequestParam Long id) {
       workFlowDocService.delete(id);
        return ResultBean.defaultSuccessResult();
    }

    @RequiresPermissions("workflow:doc:save")
    @PostMapping("/save")
    @ApiOperation(value = "保存文档清单" , response = WorkFlowDoc.class)
    public ResultBean save(@RequestBody WorkFlowDocBean bean) {
        return workFlowDocService.save(bean);
    }


}
